package springboot.config;

import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springboot.service.AgvService;
import springboot.service.impl.AgvServiceImpl;

import javax.xml.ws.Endpoint;


@Configuration
public class CxfConfig {
    //方法的名称不能是dispatcherServlet，改为dispatcherServlet2深坑啊，害我用了一个低版本的springboot
    @Bean
    public ServletRegistrationBean dispatcherServlet2() {
        return new ServletRegistrationBean(new CXFServlet(),"/agv/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    @Bean
    public AgvService demoService() {
        return new AgvServiceImpl();
    }

    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), demoService());
        endpoint.publish("/agvService");
        return endpoint;
    }
}
